//
//  InviteListRootViewController.m
//  CBT
//
//  Created by Mr.Zhang on 2019/3/2.
//  Copyright © 2019 Mr.Zhang. All rights reserved.
//

#import "InviteListRootViewController.h"

#import "InviteListViewController.h"

#import "InvitationRevenueViewController.h"

@interface InviteListRootViewController ()<TYTabPagerControllerDataSource,TYTabPagerControllerDelegate>

@property (nonatomic, strong) NSArray *datas;

@end

@implementation InviteListRootViewController

#pragma mark - VC Life

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = kLocalizedString(@"邀请明细",nil);
    
    self.tabBarHeight = 68;
    self.tabBarOrignY = 0;
    
    self.tabBar.progressView.frame = CGRectMake(0, 0, 100, 1);
    self.tabBar.progressView.backgroundColor = UIColorFromRGB(0x7889FF);
    self.tabBar.layout.barStyle = TYPagerBarStyleProgressView;
    self.tabBar.layout.selectedTextFont = [UIFont boldSystemFontOfSize:16];
    self.tabBar.layout.normalTextFont   = [UIFont boldSystemFontOfSize:16];
    self.tabBar.layout.selectedTextColor= UIColorFromRGB(0x7889FF);
    self.tabBar.layout.normalTextColor  = UIColorFromRGB(0xBDBDBD);
   
    self.tabBar.layout.cellWidth = CGRectGetWidth(self.view.frame)/2;
    self.tabBar.layout.adjustContentCellsCenter = YES;
    self.tabBar.layout.progressVerEdging = 12;
    self.tabBar.collectionView.height = 40;
    self.tabBar.layout.progressWidth = 100;
    self.tabBar.layout.cellSpacing = 0;
    self.tabBar.layout.cellEdging = 0;
    self.dataSource = self;
    self.delegate = self;
    
    self.navigationController.navigationBar.hidden = NO;
    self.edgesForExtendedLayout = UIRectEdgeBottom;
    self.view.backgroundColor   = [UIColor whiteColor];
    
    [self loadData];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.subviews[0].subviews[1].hidden = YES;
}

-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.view endEditing:YES];
}

- (void)loadData {
    NSMutableArray *datas = [NSMutableArray array];
    [datas addObject:kLocalizedString(@"我的邀请",nil)];
    [datas addObject:kLocalizedString(@"邀请收益",nil)];
    _datas = [datas copy];
    
    [self scrollToControllerAtIndex:0 animate:YES];
    [self reloadData];
}

#pragma mark - TYTabPagerControllerDataSource

- (NSInteger)numberOfControllersInTabPagerController {
    return _datas.count;
}

- (UIViewController *)tabPagerController:(TYTabPagerController *)tabPagerController controllerForIndex:(NSInteger)index prefetching:(BOOL)prefetching {
    if (index == 0) {
        InviteListViewController *vc = [[InviteListViewController alloc]init];
        return vc;
    }
    else {
        InvitationRevenueViewController *vc = [[InvitationRevenueViewController alloc]init];
        vc.showType = 0;
        return vc;
    }
}

- (NSString *)tabPagerController:(TYTabPagerController *)tabPagerController titleForIndex:(NSInteger)index {
    NSString *title = _datas[index];
    return title;
}

@end
